package com.canbot.u05.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.canbot.u05.R;

import java.util.List;

/**
 * 蓝牙设备
 *
 * @author ruandan
 */
public class MyBluetoothAdapter extends BaseAdapter {

        private ViewHolder holder;

        private List<String> mList;

        private Context context;

        private LayoutInflater mInflater;

        public MyBluetoothAdapter(Context context, List<String> list) {
                this.context = context;
                this.mList = list;
        }

        @Override
        public int getCount() {
                return mList.size();
        }

        @Override
        public Object getItem(int position) {
                return null;
        }

        @Override
        public long getItemId(int position) {
                return position;
        }

        @Override
        public View getView(final int position, View convertView,
                            ViewGroup parent) {
                if (convertView == null) {
                        holder = new ViewHolder();
                        mInflater = (LayoutInflater) context
                                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        convertView = mInflater.inflate(R.layout.item_devices_list, null);
                        holder.device = (TextView) convertView.findViewById(R.id.tvName);

                        convertView.setTag(holder);
                }
                else {
                        holder = (ViewHolder) convertView.getTag();
                }
                holder.device.setText(mList.get(position));
                return convertView;
        }

        class ViewHolder {

                TextView device;

        }
}
